


#递归函数调用，递归累加数(从小到大累加)
#1 + 2 + 3 + 4 + 5 + 6 + 7 + ... +100
def func(num , count , maxCount):
    if count > maxCount:
        return num
    num = num + count
    return func(num , count + 1 , maxCount)

#递归函数调用，递归累加数(从大到小累加)
#100 + 99 +  ... +
def func2(total_num , count):
    if count == 0:
        return total_num
    total_num = total_num + count
    return func2(total_num , count - 1)




#1+2+3+...+100
total = func(0 , 1 , 100)
print("total=" , total)

#100+99+...+1
total = func2(0 , 100)
print("total=" , total)


#只需要一个参数增加
def sum_n(n):
    if n == 1:
        return 1
    else:
        return sum_n(n-1) + n

total = sum_n(100)
print("total=" , total)


#阶乘计算  1*2*3*...*n
def sum_sn(n):
    if n == 1:
        return 1
    else:
        return sum_sn(n-1) + n

total = sum_sn(3)
print("total=" , total)


#斐波那契数列  1 1 2 3 5 8 13 21 ....
def sum_s2(n):
    if n == 1 or n == 2:
        return 1
    else:
        return sum_s2(n-1) + sum_s2(n-2)

total = sum_s2(7)
print("total=" , total)